package com.cham.video.controller;

import com.cham.enums.ChamSysCodeEnum;
import com.cham.utils.TokenUtils;
import com.cham.video.entity.ChamVideo;
import com.cham.video.entity.ChamVideoFenzu;
import com.cham.video.service.VideoService;
import com.cham.xinfan.entity.ChamXinfanFenzu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.nio.channels.FileChannel;
import java.util.Date;
import java.util.List;

/**
 * @author Howl-Xu
 * @version 1.0.0
 * @Description: 请描述一下这个类文件吧
 * @createTime 2020年03月15日 17:14:00
 */
@Controller
@RequestMapping("/fenzuController")
public class FenzuController {

    @Autowired
    private VideoService videoService;


    @GetMapping("/getXinfanFenzu")
    @ResponseBody
    @Transactional
    public List<ChamVideoFenzu> getXinfanFenzu(){
        return videoService.getXinfanFenzu();
    }



    @GetMapping("/addNewXinfanFenzu")
    @ResponseBody
    @Transactional
    public ChamSysCodeEnum addNewXinfanFenzu(String newFenzuName){
        videoService.addNewXinfanFenzu(newFenzuName);
        return ChamSysCodeEnum.ADD_XINFAN_FENZU_SUCCESS;
    }

    @GetMapping("/addNewNormalFenzu")
    @ResponseBody
    @Transactional
    public ChamSysCodeEnum addNewNormalFenzu(String newFenzuName){
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String token = request.getHeader("token");
        String userUUID = TokenUtils.getLoginUserUUID(token);
        videoService.addNewNormalFenzu(newFenzuName,userUUID);
        return ChamSysCodeEnum.ADD_NORMAL_FENZU_SUCCESS;
    }

    @GetMapping("/getFenzuInfoByUUID")
    @ResponseBody
    @Transactional
    public List<ChamVideoFenzu> getFenzuInfoByUUID(){
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String token = request.getHeader("token");
        String userUUID = TokenUtils.getLoginUserUUID(token);
        return videoService.getFenzuInfoByUUID(userUUID);
    }

}
